﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterAdmin.master" AutoEventWireup="true" CodeBehind="MeterialList.aspx.cs" Inherits="Project_Udrinkwater.PagesAdmin.MeterialList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Panel ID="Panel1" runat="server">
        <table style="width: 100%">
            <tr>
                <td style="width: 222px">
                    &nbsp;</td>
                <td style="width: 182px">
                    &nbsp;</td>
                <td style="width: 442px">
                    &nbsp;</td>
                <td align="right" style="width: 477px">
                    &nbsp;</td>
                <td align="right" style="width: 477px">
                    <asp:Label ID="Label4" runat="server" Text="เลขที่เอกสาร:"></asp:Label>
                </td>
                <td>
                    <dx:ASPxTextBox ID="txtDocNO" runat="server" ReadOnly="True" Width="250px">
                    </dx:ASPxTextBox>
                </td>
            </tr>
            <tr>
                <td style="height: 23px; width: 222px">
                    &nbsp;</td>
                <td style="height: 23px; width: 182px">
                    &nbsp;</td>
                <td align="right" style="height: 23px; width: 442px">
                    &nbsp;</td>
                <td align="left" style="height: 23px; width: 477px">
                    &nbsp;</td>
                <td align="right" style="height: 23px; width: 477px">
                    <asp:Label ID="Label5" runat="server" Text="วันที่เอกสาร:"></asp:Label>
                </td>
                <td style="height: 23px">
                    <dx:ASPxTextBox ID="txtDateDoc" runat="server" ReadOnly="True" Width="250px">
                    </dx:ASPxTextBox>
                </td>
            </tr>
            <tr>
                <td style="height: 23px; width: 222px">
                    <asp:Label ID="Label2" runat="server" Text="ชื่อผู้ขาย:"></asp:Label>
                </td>
                <td style="height: 23px; width: 182px">
                    <dx:ASPxTextBox ID="txtSplierName" runat="server" ReadOnly="True" Width="250px">
                    </dx:ASPxTextBox>
                </td>
                <td align="right" style="height: 23px; width: 442px">
                    <asp:Label ID="Label1" runat="server" Text="วันที่กำหนดส่ง:"></asp:Label>
                </td>
                <td align="left" style="height: 23px; width: 477px">
                    <dx:ASPxTextBox ID="txtDueDate" runat="server" ReadOnly="True" 
                        style="margin-top: 0px" Width="250px">
                    </dx:ASPxTextBox>
                </td>
                <td align="right" style="height: 23px; width: 477px">
                    &nbsp;</td>
                <td style="height: 23px">
                    &nbsp;</td>
            </tr>
            <tr>
                <td align="right" style="width: 222px">
                    &nbsp;</td>
                <td style="width: 182px">
                    &nbsp;</td>
                <td align="right" style="width: 442px">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
                <td style="width: 477px">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td align="right" style="width: 222px">
                    <asp:Label ID="Label3" runat="server" Text="ที่อยู่:"></asp:Label>
                </td>
                <td rowspan="3" style="width: 182px">
                    <dx:ASPxMemo ID="txtAddress" runat="server" Height="84px" ReadOnly="True" 
                        Width="250px">
                    </dx:ASPxMemo>
                </td>
                <td align="right" style="width: 442px">
                    <asp:Label ID="Label6" runat="server" Text="เงื่อนไขการชำระ:"></asp:Label>
                </td>
                <td colspan="3">
                    <dx:ASPxTextBox ID="txtCondition" runat="server" ReadOnly="True" Width="250px">
                    </dx:ASPxTextBox>
                </td>
            </tr>
            <tr>
                <td style="width: 222px">
                    &nbsp;</td>
                <td style="width: 442px">
                    &nbsp;</td>
                <td colspan="3">
                    &nbsp;</td>
            </tr>
            <tr>
                <td style="width: 222px">
                    &nbsp;</td>
                <td style="width: 442px">
                    &nbsp;</td>
                <td colspan="3" align="right">
                    &nbsp;</td>
            </tr>
        </table>
        
    </asp:Panel>
    <asp:Panel ID="Panel2" runat="server">
        <dx:ASPxGridView ID="gvDetial" runat="server" Width="100%" 
            AutoGenerateColumns="False" DataSourceID="SqlDetialGV" 
            KeyFieldName="Material_List_No" 
            onbeforeperformdataselect="gvDetial_BeforePerformDataSelect">
            <Columns>
                <dx:GridViewCommandColumn VisibleIndex="10" Caption="ทำรายการ">
                    <EditButton Visible="True" Text="แก้ไข">
                    </EditButton>
                    <NewButton Visible="True" Text="เพิ่ม">
                    </NewButton>
                    <DeleteButton Visible="True" Text="ลบ">
                    </DeleteButton>
                    <CancelButton Text="ยกเลิก">
                    </CancelButton>
                    <UpdateButton Text="ตกลง">
                    </UpdateButton>
                    <ClearFilterButton Text="ยกเลิก" Visible="True">
                    </ClearFilterButton>
                </dx:GridViewCommandColumn>
                <dx:GridViewDataTextColumn FieldName="Order_Material_ID" VisibleIndex="0" 
                    Visible="False">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="Order_Material_doc_NO" ReadOnly="True" 
                    VisibleIndex="2" Visible="False" Caption="เลขที่เอกสาร">
                    <PropertiesTextEdit DisplayFormatString="dd/MM/yyyy">
                    </PropertiesTextEdit>
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="Row" ReadOnly="True" 
                    VisibleIndex="1" Caption="ลำดับ">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="Material_List_No" VisibleIndex="3" 
                    ReadOnly="True" Visible="False">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="Product_ID" VisibleIndex="4" 
                    Caption="สินค้า" Width="250px">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataComboBoxColumn Caption="ประเภทสินค้า" 
                    FieldName="Product_Category_ID" VisibleIndex="5" Visible="False">
                    <PropertiesComboBox DataSourceID="SqlCate" TextField="Product_Category_Name" 
                        ValueField="Product_Category_ID">
                    </PropertiesComboBox>
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataComboBoxColumn>
                <dx:GridViewDataTextColumn FieldName="Amount" VisibleIndex="6" 
                    Caption="จำนวน">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="ราคา/หน่วย" FieldName="Price" 
                    VisibleIndex="7">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="ส่วนลด" FieldName="Discount" 
                    VisibleIndex="8">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Caption="รวม" FieldName="Total" ReadOnly="True" 
                    VisibleIndex="9">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
            </Columns>
            <Settings ShowFilterRow="True" ShowFooter="True" />
            <TotalSummary>
            <dx:ASPxSummaryItem DisplayFormat="รวม {0:#,###.00}" FieldName="Total" 
                                    ShowInColumn="Total" ShowInGroupFooterColumn="Total" 
                SummaryType="Sum" />
        </TotalSummary>
        </dx:ASPxGridView> 
        <asp:SqlDataSource ID="SqlDetialGV" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" DeleteCommand="DELETE FROM TB_Order_Material_List
WHERE (Material_List_No =@Material_List_No)" 
            InsertCommand="INSERT INTO TB_Order_Material_List(Order_Material_ID, Product_ID, Product_Category_ID, Amount, Price, Discount) VALUES (@Order_Material_ID, @Product_ID, @Product_Category_ID, @Amount, @Price, @Discount);" 
            SelectCommand="SELECT TB_Order_Material_List.Order_Material_ID, TB_Order_Material.Order_Material_doc_NO,ROW_NUMBER() OVER(ORDER BY TB_Order_Material_List.Order_Material_ID DESC) AS Row ,TB_Order_Material_List.Material_List_No, TB_Order_Material_List.Product_ID, TB_Order_Material_List.Product_Category_ID, TB_Order_Material_List.Amount, TB_Order_Material_List.Price, TB_Order_Material_List.Discount, (TB_Order_Material_List.Amount * TB_Order_Material_List.Price )- TB_Order_Material_List.Discount AS Total FROM TB_Order_Material_List INNER JOIN TB_Order_Material ON TB_Order_Material_List.Order_Material_ID = TB_Order_Material.Order_Material_ID WHERE (TB_Order_Material_List.Order_Material_ID = @Order_Material_ID)" 
            
            
            
            
            UpdateCommand="UPDATE TB_Order_Material_List SET Product_ID =@Product_ID , Product_Category_ID =@Product_Category_ID , Amount =@Amount , Price =@Price , Discount =@Discount WHERE (Material_List_No =@Material_List_No)">
            <DeleteParameters>
                <asp:Parameter Name="Material_List_No" />
            </DeleteParameters>
            <InsertParameters>
               <asp:SessionParameter DefaultValue="" Name="Order_Material_ID" 
                    SessionField="Order_Material_ID" />
                <asp:Parameter Name="Product_ID" />
                <asp:Parameter Name="Product_Category_ID" />
                <asp:Parameter Name="Amount" />
                <asp:Parameter Name="Price" />
                <asp:Parameter Name="Discount" />
            </InsertParameters>
            <SelectParameters>
                <asp:SessionParameter DefaultValue="" Name="Order_Material_ID" 
                    SessionField="Order_Material_ID" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="Product_ID" />
                <asp:Parameter Name="Product_Category_ID" />
                <asp:Parameter Name="Amount" />
                <asp:Parameter Name="Price" />
                <asp:Parameter Name="Discount" />
                <asp:Parameter Name="Material_List_No" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlMainGV" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
            
            SelectCommand="SELECT TB_Order_Material.Order_Material_ID, TB_Order_Material.Order_Material_doc_NO, TB_Order_Material.Order_material_Date, TB_Order_Material.Supplier_ID, TB_Order_Material.Due_Date, TB_Order_Material.Condition_Pay, TB_Supplier.Supplier_Name, (TB_Supplier.Adress +' โทร. '+ TB_Supplier.Phone +' แฟกส์ .'+ TB_Supplier.Fax ) AS Adress FROM TB_Order_Material INNER JOIN TB_Supplier ON TB_Order_Material.Supplier_ID = TB_Supplier.Supplier_ID WHERE (TB_Order_Material.Order_Material_ID = @Order_Material_ID)" 
            onselecting="SqlMainGV_Selecting">
            <SelectParameters>
                <asp:Parameter Name="Order_Material_ID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlProduct" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
            SelectCommand="SELECT [Product_ID], [Product_Name] FROM [TB_Product]">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlCate" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
            SelectCommand="SELECT * FROM [TB_Product_Category]"></asp:SqlDataSource>
    </asp:Panel>
</asp:Content>
